package com.chris.homecare.screens
{
	import com.chris.homecare.components.BreadcrumbComponenet;
	import com.chris.homecare.components.BulletHeadingComp;
	import com.chris.homecare.components.HeaderComponent;
	import com.chris.homecare.components.renderers.JobsListRenderer;
	import com.chris.homecare.data.DataUtil;
	import com.chris.homecare.utils.CommonUtils;
	import com.chris.homecare.utils.ScreenNames;
	
	import feathers.controls.List;
	import feathers.controls.Screen;
	import feathers.controls.renderers.IListItemRenderer;
	import feathers.layout.VerticalLayout;
	
	import starling.display.Quad;
	import starling.events.Event;
	
	[Event(name="triggerJobScreen",type="starling.events.Event")]
	
	public class JobsListScreen extends Screen
	{
		public static const TRIGGER_JOB_SCREEN:String = "triggerJobScreen";
		
		private var headerComp:HeaderComponent;
		private var breadcrumbComp:BreadcrumbComponenet;
		private var jobsList:List;
		private var bulletHeadingComp:BulletHeadingComp;
		public function JobsListScreen()
		{
			super();
		}
		
		override protected function initialize():void
		{
			CommonUtils.previousScreen = ScreenNames.MENU_SCREEN;
			
			var layout:VerticalLayout = new VerticalLayout();
			this.layout = layout;
			
			headerComp = new HeaderComponent();
			headerComp.addEventListener(Event.COMPLETE, onMenuBtnTrigger);
			addChild(headerComp);
			
			breadcrumbComp = new BreadcrumbComponenet("Jobs List");
			addChild(breadcrumbComp);
			
			bulletHeadingComp = new BulletHeadingComp("Jobs");
			addChild(bulletHeadingComp);
			
			jobsList = new List();
			jobsList.dataProvider = DataUtil.getAllJobs();
			jobsList.itemRendererFactory = function ():IListItemRenderer
			{
				var renderer:JobsListRenderer = new JobsListRenderer();
				return renderer;
			};
			jobsList.addEventListener(Event.CHANGE, onJobListChange);
			addChild(jobsList);
			jobsList.backgroundSkin = new Quad(10,10,0xFFFFFF);
			jobsList.backgroundDisabledSkin = new Quad(10,10,0xFFFFFF);
			
			super.initialize();
		}
		
		override protected function draw():void
		{
			jobsList.width = stage.stageWidth;
			jobsList.height = stage.stageHeight - jobsList.y - 20*CommonUtils.scaleValue;
			super.draw();
		}
		
		private function onMenuBtnTrigger(event:Event):void
		{
			this.dispatchEventWith(Event.COMPLETE);
		}
		
		private function onJobListChange(event:Event):void
		{
			this.dispatchEventWith(TRIGGER_JOB_SCREEN,false,jobsList.selectedItem);
		}
	}
}